/*
 * mem.h
 *
 * Edited by: krishna
 */


#ifndef MEM_H
#define MEM_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "shared.h"

/* mips defines */

/* registers */
#define MIPS_FP  "$fp"
#define MIPS_SP  "$sp"
#define MIPS_GP "$gp"
#define MIPS_RA "$ra"
#define MIPS_V0 "$v0"       /* syscall */
#define MIPS_PRINT_A0 "$a0"     
#define MIPS_GLOBAL_PARENT_S0 "$s0"
#define MIPS_FUNC_RETURN_S1 "$v1"
#define MIPS_LO "$lo"    
#define OUT_YOU_GO "out_you_go"    

#define MIPS_FUNC_GLOBALS_SIZE 32
#define MIPS_FUNC_PA_CLASS_OFFSET 0
#define MIPS_FUNC_PA_FUNC_OFFSET 8
#define MIPS_FUNC_RA_OFFSET 16
#define MIPS_PRINT_CALL 1
#define CMD_ADD_I "addi"
#define CMD_STORE_WORD "sw"

/* types */
#define TYPE_CLASS_MEMORY 0
#define TYPE_FUNCTION_MEMORY 1
#define TYPE_TEMP_REGISTER 2
#define TYPE_TEMP_REGISTER_MEMORY 3

/* temp cariable details */
#define VAR_COUNT 10

/* some other important definitiions */
#define MIPS_SYS_CALL "syscall"
#define MIPS_EXIT_CALL 10
#define MIPS_NEWLINE "newline"

#define NOT_SET -1

struct operand_t
    {
    char   lexeme [32];   
    char * class;
    char * func;
    char * type_name;
    char * var_name;
    int    type; /* #define TYPE_CLASS_MEMORY 0
                    #define TYPE_FUNCTION_MEMORY 1 
                    #define TYPE_TEMP_REGISTER 2 
                    #define TYPE_TEMP_REGISTER_MEMORY 3*/
    int offset;
    };

struct temp_variables_t
    {
    int contains_address_flag;
    int inuse;
    char var_inuse[32];
    char name [32];
    char * type_name; // used in case the class name of the variable must persist through to another call
    char * var_name; // used in case the variable name of the variable must persist through to another call
    } ;

struct temp_variables_t temp_variables[VAR_COUNT];


void push_tmp_variable (char * name);
void print_tmp_variables();
struct temp_variables_t * pop_tmp_variable (char * var, int contains_memory_flag);
void init_tmp_variables ();

#endif /* MEM_H */
